<template>
  <div>
    <div class="seed_top_banner" style="border-bottom: 0.1rem solid #E5E5E5">
      <div class="seed_back_arrow" @click="back">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-zuo"></use>
        </svg>
      </div>
      <div class="seed_page_title"><span>编辑</span></div>
      <div class="seed_page_tool"></div>
    </div>
    <form>
      <div class="seed_user_edit_mysecond">
        <div class="seed_user_edit_list">
          <p>用户名</p>
          <input type="text" class="seed_user_edit_jt" v-model="info.realname" placeholder="请输入用户名称"/>
        </div>
        <div class="seed_user_edit_list">
          <p>手机号码</p>
          <input type="number" class="seed_user_edit_jt" v-model="info.mobile" placeholder="请输入手机号"/>
        </div>
        <div class="seed_user_edit_list">
          <p>邮箱</p>
          <input type="email" class="seed_user_edit_jt" v-model="info.email" placeholder="请输入邮箱"/>
        </div>
        <div class="seed_member_edit_line"></div>
        <div class="seed_member_edit_list">
          <p class="seed_member_edit_p">备注</p>
          <textarea class="seed_member_edit_textarea" placeholder="请输入备注" style="padding: 0.5rem" v-model="info.remark"></textarea>
        </div>
      </div>
      <input class="seed_user_edit_submit" type="button" value="确认修改" @click="submitForm()"/>
    </form>
  </div>
</template>
<script>
import * as validator from '@/validator'
export default {
  data () {
    return {
      info: {
        mobile: '',
        realname: '',
        email: '',
        remark: '',
        admin_id: 0
      }
    }
  },
  created () {
    this.info.admin_id = this.$route.params.id
    this.getInfo()
  },
  methods: {
    back () {
      this.$router.push({name: 'my-manager_set'})
    },
    getInfo () {
      let param = {admin_id: this.$route.params.id}
      this.$request.ManagerEdit(param).then(data => {
        this.info = data
      })
    },
    check () {},
    submitForm () {
      let data = this.info
      data.admin_id = this.$route.params.id
      data.save = 1
      if (data.realname === '') {
        this.$toast('用户名称不能为空')
        return false
      }
      if (!validator.phone(data.mobile)) {
        this.$toast('请输入有效手机号')
        return false
      }
      if (!validator.email(data.email)) {
        this.$toast('请输入有效邮箱')
        return false
      }
      this.$MessageBox.confirm('确定要保存修改吗?').then(action => {
        this.$request.ManagerEdit(data).then(data => {
          this.$toast('保存成功')
        })
      })
    }
  }
}
</script>
